package com.example.app2024;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.DisplayCutout;
import android.view.View;
import android.view.Window;
import android.view.WindowInsets;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.app2024.CustomView.Atoz.AtoZActivity;
import com.example.app2024.CustomView.CurstomViewActivity;
import com.example.app2024.Gestrue.GroupAndGuestrureActivity;
import com.example.app2024.Gestrue.GuestrueActivity;
import com.example.app2024.TransitionAnimat.activity.FirstActivity;
import com.example.app2024.TransitionAnimat.scene.SceneActivity;
import com.example.app2024.TransitionAnimat.transAnimateActivity;
import com.example.app2024.UDP.HttpActivity;
import com.example.app2024.UDP.TcpActivity;
import com.example.app2024.UDP.UDPActivity;
import com.example.app2024.aidl.AIDLActivity;
import com.example.app2024.animate.AnimateActivity;
import com.example.app2024.appbar.AppbarActivity;
import com.example.app2024.boardcast.myboardcastActivity;
import com.example.app2024.buttomNavi.ButtomNaviActivity;
import com.example.app2024.canvas.canvasActivity;
import com.example.app2024.cat.CatActivity;
import com.example.app2024.controls.ApplistActivity;
import com.example.app2024.fragment.FragmentDemoActivity;
import com.example.app2024.fragment.FragmentDymicActivity;
import com.example.app2024.h5.H5Activity;
import com.example.app2024.handle.HandleActivity;
import com.example.app2024.infosave.infosaveActivity;
import com.example.app2024.local.Local118Activity;
import com.example.app2024.mnote.MnoteActivity;
import com.example.app2024.myprovider.MyProviderActivity;
import com.example.app2024.navigation.NavigationActivity;
import com.example.app2024.navigationview.NaviActivity;
import com.example.app2024.note.NoteActivity;
import com.example.app2024.phonenum.PhoneNumActivity;
import com.example.app2024.picflop.FlipActivity;
import com.example.app2024.recylerViewdemo.recylerdemoActivity;
import com.example.app2024.sensor.SensorActivity;
import com.example.app2024.service.ServiceDemoActivity;
import com.example.app2024.sqlite.SqliteActivity;
import com.example.app2024.svg.MyMapviewActivity;
import com.example.app2024.tab.tabActivity;
import com.example.app2024.tablayout.activity.TabLayoutMainActivity;
import com.example.app2024.temp.tempActivity;
import com.example.app2024.threadsafe.threadActivity;
import com.example.app2024.toolbar.ToolbarActivity;
import com.example.app2024.viewmodel.ViewModelActivity;
import com.example.app2024.viewpagerAD.ViewpagerView;
import com.example.app2024.wechatr.WechatActivity;
import com.example.app2024.xigua.xiguaActivity;

public class MainActivity extends AppCompatActivity
{
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
            super.onCreate(savedInstanceState);
            EdgeToEdge.enable(this);
            
            //            supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
            //            Window window = getWindow();
            //            window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  //全屏
            
            //判断手机是不是刘海屏
            //            boolean hasDisplayCoutout = hasDisplayCutout(window);
            //            if (hasDisplayCoutout)  //判断了有刘海, 再进行全屏
            //            {
            //                  //api android 9 以上使用
            //                  WindowManager.LayoutParams attributes = window.getAttributes();
            //                  //LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT 全屏模式下内容下移, 非全屏不受影响
            //                  // edges 允许内容进入刘海区
            //                  //never 不允许内容进入刘海
            //                  attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            //                  window.setAttributes(attributes);
            //                  int flags = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
            //                  int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
            //                  systemUiVisibility |= flags;  //追加设置
            //                  window.getDecorView().setSystemUiVisibility(systemUiVisibility);
            //            }
            
            
            setContentView(R.layout.activity_main);
            ViewCompat.setOnApplyWindowInsetsListener(
                    findViewById(R.id.main), (v, insets) -> {
                          Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                          v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
                          return insets;
                    });
            
            
      }
      
      private boolean hasDisplayCutout(Window window)
      {
            DisplayCutout displayCutout;
            View rootView = window.getDecorView();
            WindowInsets insets = rootView.getRootWindowInsets();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && insets != null) //判断版本
            {
                  displayCutout = insets.getDisplayCutout();
                  if (displayCutout != null)
                  {
                        if (displayCutout.getBoundingRects() != null && displayCutout.getBoundingRects().size() > 0 && displayCutout.getSafeInsetTop() > 0)
                        {
                              return true;
                        }
                  }
                  
            }
            //TODO 这里应该返回 false , 但是真实手机不知道为什么只能为true, 所以现在这个方法无意义, 以后要改进
            return true;
      }
      
      public int heightForDisplayCoutout()  //取刘海高度
      {
            int resID = getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resID > 0)
            {
                  return getResources().getDimensionPixelSize(resID);
            }
            return 96;  //通常情况 下,  刘海的高就是状态栏的高
      }
      
      public void 仿微信界面(View view)
      {
            Intent intent = new Intent(this, WechatActivity.class);
            startActivity(intent);
      }
      
      public void 记事本(View view)
      {
            Intent intent = new Intent(this, NoteActivity.class);
            startActivity(intent);
      }
      
      public void sqlite(View view)
      {
            
            Intent intent = new Intent(this, SqliteActivity.class);
            startActivity(intent);
      }
      
      public void fragmentStatic(View view)
      {
            Intent intent = new Intent(this, FragmentDemoActivity.class);
            startActivity(intent);
      }
      
      public void fragmentdaymic(View view)
      {
            Intent intent = new Intent(this, FragmentDymicActivity.class);
            startActivity(intent);
      }
      
      public void toolbaruse(View view)
      {
            Intent intent = new Intent(this, ToolbarActivity.class);
            startActivity(intent);
      }
      
      public void mynavi(View view)
      {
            Intent intent = new Intent(this, NaviActivity.class);
            startActivity(intent);
      }
      
      public void mytab(View view)
      {
            Intent intent = new Intent(this, tabActivity.class);
            startActivity(intent);
      }
      
      
      public void appbar(View view)
      {
            Intent intent = new Intent(this, AppbarActivity.class);
            startActivity(intent);
      }
      
      public void buttomnavi(View view)
      {
            Intent intent = new Intent(this, ButtomNaviActivity.class);
            startActivity(intent);
      }
      
      public void xigua(View view)
      {
            Intent intent = new Intent(this, xiguaActivity.class);
            startActivity(intent);
      }
      
      public void daocount(View view)
      {
            Intent intent = new Intent(this, com.example.app2024.counttime.MainActivity.class);
            startActivity(intent);
      }
      
      public void getphonenum(View view)
      {
            Intent intent = new Intent(this, PhoneNumActivity.class);
            startActivity(intent);
      }
      
      public void getCat(View view)
      {
            Intent intent = new Intent(this, CatActivity.class);
            startActivity(intent);
      }
      
      
      public void picFlip(View view)
      {
            Intent intent = new Intent(this, FlipActivity.class);
            startActivity(intent);
      }
      
      public void mnote(View view)
      {
            Intent intent = new Intent(this, MnoteActivity.class);
            startActivity(intent);
      }
      
      public void drawboard(View view)
      {
            Intent intent = new Intent(this, com.example.app2024.draw.MainActivity.class);
            startActivity(intent);
      }
      
      public void dohandle(View view)
      {
            Intent intent = new Intent(this, HandleActivity.class);
            startActivity(intent);
      }
      
      public void dolocal(View view)
      {
            Intent intent = new Intent(this, Local118Activity.class);
            startActivity(intent);
      }
      
      public void doviewmdel(View view)
      {
            Intent intent = new Intent(this, ViewModelActivity.class);
            startActivity(intent);
      }
      
      public void donavigation(View view)
      {
            Intent intent = new Intent(this, NavigationActivity.class);
            startActivity(intent);
      }
      
      public void doButtomnavigation(View view)
      {
            Intent intent = new Intent(this, com.example.app2024.navigationButtom.ButtomNaviActivity.class);
            startActivity(intent);
      }
      
      
      public void docustomview01(View view)
      {
            Intent intent = new Intent(this, CurstomViewActivity.class);
            startActivity(intent);
      }
      
      public void do26letter(View view)
      {
            Intent intent = new Intent(this, AtoZActivity.class);
            startActivity(intent);
      }
      
      public void doapplist(View view)
      {
            Intent intent = new Intent(this, ApplistActivity.class);
            startActivity(intent);
      }
      
      public void doinfosave(View view)
      {
            Intent intent = new Intent(this, infosaveActivity.class);
            startActivity(intent);
      }
      
      public void docast(View view)
      {
            Intent intent = new Intent(this, myboardcastActivity.class);
            startActivity(intent);
      }
      
      public void doreclyerview(View view)
      {
            Intent intent = new Intent(this, recylerdemoActivity.class);
            startActivity(intent);
      }
      
      public void doService(View view)
      {
            Intent intent = new Intent(this, ServiceDemoActivity.class);
            startActivity(intent);
      }
      
      public void doContentProvider(View view)
      {
            Intent intent = new Intent(this, MyProviderActivity.class);
            startActivity(intent);
      }
      
      public void donetwork(View view)
      {
            Intent intent = new Intent(this, UDPActivity.class);
            startActivity(intent);
      }
      
      public void dohttp(View view)
      {
            Intent intent = new Intent(this, HttpActivity.class);
            startActivity(intent);
      }
      
      public void dotcp(View view)
      {
            Intent intent = new Intent(this, TcpActivity.class);
            startActivity(intent);
      }
      
      public void doanimate(View view)
      {
            Intent intent = new Intent(this, AnimateActivity.class);
            startActivity(intent);
      }
      
      public void doTransAnimate(View view)
      {
            Intent intent = new Intent(this, transAnimateActivity.class);
            startActivity(intent);
      }
      
      public void domTransAnimate(View view)
      {
            Intent intent = new Intent(this, SceneActivity.class);
            startActivity(intent);
      }
      
      public void domTransActivity(View view)
      {
            Intent intent = new Intent(this, FirstActivity.class);
            startActivity(intent);
      }
      
      public void domSurfaceGame(View view)
      {
            Intent intent = new Intent(this, com.example.app2024.SurfaceGame.MainActivity.class);
            startActivity(intent);
      }
      
      public void dothread(View view)
      {
            Intent intent = new Intent(this, threadActivity.class);
            startActivity(intent);
      }
      
      public void doaidl(View view)
      {
            Intent intent = new Intent(this, AIDLActivity.class);
            startActivity(intent);
      }
      
      public void dosensor(View view)
      {
            Intent intent = new Intent(this, SensorActivity.class);
            startActivity(intent);
      }
      
      public void docanvas(View view)
      {
            Intent intent = new Intent(this, canvasActivity.class);
            startActivity(intent);
      }
      
      public void dosvg(View view)
      {
            Intent intent = new Intent(this, MyMapviewActivity.class);
            startActivity(intent);
      }
      
      public void doviewpaerad(View view)
      {
            Intent intent = new Intent(this, ViewpagerView.class);
            startActivity(intent);
      }
      
      public void dotemp(View view)
      {
            Intent intent = new Intent(this, tempActivity.class);
            startActivity(intent);
      }
      
      public void dotGuestrue(View view)
      {
            Intent intent = new Intent(this, GuestrueActivity.class);
            startActivity(intent);
      }
      
      public void dogroupAndGuestrue(View view)
      {
            Intent intent = new Intent(this, GroupAndGuestrureActivity.class);
            startActivity(intent);
      }
      
      public void doh5(View view)
      {
            Intent intent = new Intent(this, H5Activity.class);
            startActivity(intent);
      }
      
      public void doreclyerview2016(View view)
      {
            Intent intent = new Intent(this, recylerdemoActivity.class);
            startActivity(intent);
      }
      
      public void dotablayout2016(View view)
      {
            Intent intent = new Intent(this, TabLayoutMainActivity.class);
            startActivity(intent);
      }
}